[broadway] Serialize event times
authorAlexander Larsson <alexl@redhat.com>
Thu, 7 Apr 2011 17:12:51 +0000 (19:12 +0200)
committerAlexander Larsson <alexl@redhat.com>
Thu, 7 Apr 2011 17:12:51 +0000 (19:12 +0200)
Event times come from the browser and may change weirdly when we reconnect
with another browser, so we normalize these to be strictly increasing
and with a 5 second gap for each reconnect.

gdk/broadway/gdkdevice-broadway.c
gdk/broadway/gdkdisplay-broadway.c
gdk/broadway/gdkdisplay-broadway.h
gdk/broadway/gdkeventsource.c

index 11bfe53e00149f8a520087cfc02ccbe1b27e76c7..6b514ea2d88547d3604a02fbabf676392298df84 100644 (file)
@@ -263,7 +263,7 @@ gdk_broadway_device_grab (GdkDevice    *device,
        return GDK_GRAB_ALREADY_GRABBED;
 
       if (time_ == 0)
-       time_ = broadway_display->last_event_time;
+       time_ = broadway_display->last_seen_time;
 
       broadway_display->pointer_grab_window = window;
       broadway_display->pointer_grab_owner_events = owner_events;
index b39d4e120435a425076458d9ad7cc7a946b7e33c..17b876b63e1d1cd5b36855cd0e7c5654207c4e3d 100644 (file)
@@ -62,6 +62,7 @@ gdk_event_init (GdkDisplay *display)
   broadway_display = GDK_BROADWAY_DISPLAY (display);
   broadway_display->event_source = _gdk_broadway_event_source_new (display);
   broadway_display->saved_serial = 1;
+  broadway_display->last_seen_time = 1;
 }
 
 static void
@@ -137,6 +138,8 @@ struct BroadwayInput {
   GSocketConnection *connection;
   GByteArray *buffer;
   GSource *source;
+  gboolean seen_time;
+  gint64 time_base;
 };
 
 static void
@@ -200,6 +203,7 @@ parse_input_message (BroadwayInput *input, const char *message)
   GdkBroadwayDisplay *broadway_display;
   BroadwayInputMsg msg;
   char *p;
+  gint64 time_;
 
   broadway_display = GDK_BROADWAY_DISPLAY (input->display);
 
@@ -207,9 +211,26 @@ parse_input_message (BroadwayInput *input, const char *message)
   msg.base.type = *p++;
   msg.base.serial = (guint32)strtol (p, &p, 10);
   p++; /* Skip , */
-  msg.base.time = strtol(p, &p, 10);
+  time_ = strtol(p, &p, 10);
   p++; /* Skip , */
 
+  if (time_ == 0) {
+    time_ = broadway_display->last_seen_time;
+  } else {
+    if (!input->seen_time) {
+      input->seen_time = TRUE;
+      /* Calculate time base so that any following times are normalized to start
+        5 seconds after last_seen_time, to avoid issues that could appear when
+        a long hiatus due to a reconnect seems to be instant */
+      input->time_base = time_ - (broadway_display->last_seen_time + 5000);
+    } 
+    time_ = time_ - input->time_base;
+  }
+
+  broadway_display->last_seen_time = time_;
+
+  msg.base.time = time_;
+
   switch (msg.base.type) {
   case 'e': /* Enter */
   case 'l': /* Leave */
index 029e88d6c3d42774b0f1b6367d71f908e3fc584b..433c9b4c6cf64fdbc903228e55851f520bb69084 100644 (file)
@@ -150,21 +150,17 @@ struct _GdkBroadwayDisplay
   /* input GdkDevice list */
   GList *input_devices;
 
-  /* Time of most recent user interaction. */
-  gulong user_time;
-
   /* The offscreen window that has the pointer in it (if any) */
   GdkWindow *active_offscreen_window;
 
   GSocketService *service;
   BroadwayOutput *output;
   guint32 saved_serial;
+  guint64 last_seen_time;
   BroadwayInput *input;
   GList *input_messages;
   guint process_input_idle;
 
-  guint64 last_event_time;
-
   /* Explicit pointer grabs: */
   GdkWindow *pointer_grab_window;
   guint32 pointer_grab_time;
index 6cefc4772634c7c2a80a72b7d874a35b9ff1a5e1..a2864daf0ab3a7854fc56a5e1569792876c79158 100644 (file)
@@ -98,8 +98,6 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
   GdkEvent *event = NULL;
   GList *node;
 
-  display_broadway->last_event_time = message->base.time;
-
   switch (message->base.type) {
   case 'e': /* Enter */
     display_broadway->last_x = message->pointer.root_x;